// $Id: exception.hpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#ifndef XPCOM_IMPL_EXCEPTION_HPP
#define XPCOM_IMPL_EXCEPTION_HPP

#include <xpcom/config.hpp>
#include <xpcom/types.hpp>

#ifdef BOOST_HAS_ABI_HEADERS
#include BOOST_ABI_PREFIX
#endif

namespace xpcom {
namespace impl {

// Translate current exception to XPCOM result code.
XPCOM_DECL result_t translate_exception();

} // namespace xpcom::impl
} // namespace xpcom

//
// Convenience macro for exception translation.
//
#define XPCOM_TRANSLATE_EXCEPTION_BEGIN \
    try {

#define XPCOM_TRANSLATE_EXCEPTION_END \
    } catch (...) { \
        return ::xpcom::impl::translate_exception(); \
    }

//
// Following macros are generated in every method implementation.
//
// For methods that are [notxpcom], these two macros will not be generated, so
// that exception will not be translated, you must handle the exceptions
// yourself, and not let the exceptions go out of interface boundary.
//
#ifndef XPCOM_DISABLE_METHOD_EXCEPTION_TRANSLATION
#  define XPCOM_IMPL_METHOD_BEGIN XPCOM_TRANSLATE_EXCEPTION_BEGIN
#  define XPCOM_IMPL_METHOD_END XPCOM_TRANSLATE_EXCEPTION_END
#else // XPCOM_DISABLE_METHOD_EXCEPTION_TRANSLATION
#  define XPCOM_IMPL_METHOD_BEGIN
#  define XPCOM_IMPL_METHOD_END
#endif // XPCOM_DISABLE_METHOD_EXCEPTION_TRANSLATION

#ifdef BOOST_HAS_ABI_HEADERS
#include BOOST_ABI_SUFFIX
#endif

#endif // XPCOM_IMPL_EXCEPTION_HPP
